package com.gaotong.science.service.impl;

import com.alibaba.excel.EasyExcel;
import com.gaotong.science.config.HightExcelListener;
import com.gaotong.science.config.MyException;
import com.gaotong.science.entity.HightTech;
import com.gaotong.science.entity.HightTechzone;
import com.gaotong.science.mapper.HightTechzoneMapper;
import com.gaotong.science.service.HightTechzoneService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author suouyang
 * @since 2021-11-03
 */
@Service
public class HightTechzoneServiceImpl extends ServiceImpl<HightTechzoneMapper, HightTechzone> implements HightTechzoneService {

    @Override
    public void importFile(MultipartFile file, HightTechzoneService hightTechzoneService) {
        try {
            //1 获取文件输入流
            InputStream inputStream = file.getInputStream();

            // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
            EasyExcel.read(inputStream, HightTech.class, new HightExcelListener(hightTechzoneService)).sheet().doRead();
        }catch(Exception e) {
            e.printStackTrace();
            throw new MyException();
        }
    }
}
